/*
 *      Author: Guannan Ma
 *      @mythmgn
 *      Whatever license applied
 */

#include <stdio.h>
#include "base.h"

#ifndef BASE_LIB_LIBCOMMON_H
#define BASE_LIB_LIBCOMMON_H

#ifdef	__cplusplus
extern "C"
{
#endif

#ifdef DEBUG
#include <assert.h>
#define ASSERT(t) assert(t)
#else
#define ASSERT(t) ;
#endif

typedef int BOOL;

/* EXBOOL contains 3 types:
 * a. TRUE B. FALSE C ERROR
 */
typedef int EXBOOL;

extern BOOL isInited;

#define FALSE 0
#define TRUE 1
#define ERROR -1

#define FREEUP(p) if(p!=NULL)\
    free(p);\
    p=NULL;

#define IN 
#define OUT


/* ***************************************************
 * Begin Maximum Len Limit
 * Descript: The maximum limit of general types for global usage
*/

#define MAX_LENGTH_OF_KEY  128 // For the keys (including hashtable and binary search(bst) )
#define MAX_LENGTH_OF_NAME 512 //The real array's length is MAX_LENGTH_OF_NAME+1
#define MAX_LENGTH_OF_DESCRIPTION 512 //for a general description
#define MAX_LENGTH_OF_FILELOCATION 512 //For the location path
#define MAX_LENGTH_OF_SHELLCOMMAND 1024 //For the shell command

/*! @description  For configuration file only
   For configuration file only */
#define MAX_LENGTH_OF_LINE 1024
#define MAX_LENGTH_OF_CONF_VALUE 512
#define MAX_LENGTH_OF_CONF_KEY 128
#define MAX_NAME_OF_FILE_NAME 1024
/* ::End  For configuration file only::  */


/*! @description For time related only */
#define MAX_LENGTH_OF_TIMER_STRING 256
#define MAX_NUMBER_OF_TIMERDIY 20


/* ::End For time related only */

/* ::Begin For pluginOnly:: */
#define MAX_LENGTH_OF_PLUGIN_NAME 64


/* For authentications */
#define MAX_USER_NAME_LEN 30
#define MAX_PASSWD_LEN 20

/*
 * End Maximum Len Limit
 *********************************************************/

    typedef struct FILEW {
        FILE *fp;
        char fname[MAX_NAME_OF_FILE_NAME];
    } FILEW;

    typedef struct strSplit {
        int pos;
        char *delimiter;
        char *splitStr;
    } strSplit;

    typedef unsigned char uint8;
    typedef unsigned short uint16;
    typedef unsigned int uint32;
    typedef unsigned long long uint64;
    typedef signed char int8;
    typedef signed short int16;
    typedef signed int int32;
    typedef signed long long int64;

strSplit* initToken(char *p_delimiter);

BOOL closeToken(strSplit *p_ss);

/*!
     @fn
          getSplitString
     @return
          If the functions return TRUE, but strlen(p_ss->splitStr)==0. That means there is no splitString between the
          end of the prevous splitString and the current matched splitString.
          E.g.
               ,aaa,bbb delimiter is ","

               The first splitString will be nothing. So strlen(p_ss->splitStr) is 0.


*/
BOOL getSplitString(char *src,strSplit *p_ss);

#define GET_ONLY_FILE_NAME(path) strrchr((path), '/')==NULL?(path):(strrchr((path), '/')+1)

#ifdef	__cplusplus
}
#endif

#endif
